package com.exam.service.impl;

import com.exam.mapper.ExamMessageMapper;
import com.exam.mapper.StudentMapper;
import com.exam.mapper.TeacherMapper;
import com.exam.pojo.ExamMessage;
import com.exam.pojo.Student;
import com.exam.pojo.Teacher;
import com.exam.service.ExamMessageService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ExamMessageServiceImpl implements ExamMessageService {
    @Resource
    private StudentMapper studentMapper;
    @Resource
    private TeacherMapper teacherMapper;
    @Resource
    private ExamMessageMapper examMessageMapper;

    @Override
    public PageInfo<ExamMessage> queryPageByStuId(Integer studentId, int pageNum, int pageSize) {
        Student student = studentMapper.queryById(studentId);
        PageHelper.startPage(pageNum,pageSize);
        List<ExamMessage> examMessages = examMessageMapper.queryByStu(student.getGrade(), student.getClazz(), student.getMajor());
        PageInfo<ExamMessage> pageInfo = new PageInfo<>(examMessages);
        return pageInfo;
    }

    @Override
    public List<ExamMessage> queryByStuId(Integer studentId) {
        Student student = studentMapper.queryById(studentId);
        List<ExamMessage> examMessages = examMessageMapper.queryByStu(student.getGrade(), student.getClazz(), student.getMajor());
        return examMessages;
    }

    @Override
    public ExamMessage queryById(Integer id) {
        return examMessageMapper.queryById(id);
    }

    @Override
    public PageInfo<ExamMessage> queryPageByTeaId(Integer teacherId, int pageNum, int pageSize) {
        Teacher teacher = teacherMapper.queryById(teacherId);
        PageHelper.startPage(pageNum,pageSize);
        List<ExamMessage> examMessages = examMessageMapper.queryByTea(teacher.getInstitute());
        PageInfo<ExamMessage> pageInfo = new PageInfo<>(examMessages);
        return pageInfo;
    }

    @Override
    public PageInfo<ExamMessage> queryPageAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<ExamMessage> examMessages = examMessageMapper.queryAll();
        PageInfo<ExamMessage> pageInfo = new PageInfo<>(examMessages);
        return pageInfo;
    }

    @Override
    public int updateById(ExamMessage examMessage) {
        return examMessageMapper.updateById(examMessage);
    }

    @Override
    public int deleteById(Integer id) {
        return examMessageMapper.deleteById(id);
    }

    @Override
    public int add(ExamMessage examMessage) {
        return examMessageMapper.insert(examMessage);
    }


}
